import React from "react";
// 非受控组件通过ref，使用原生DOM的方式来获取表单值
import {createRef} from "react";

class App extends React.Component {
    // 调用createRef创建ref对象
    txtRef = createRef();
    handleClick = () => {
        try {
            // 你的业务逻辑
            console.log(this.txtRef.current.value);
        } catch (error) {
            console.error("Error in handleClick:", error);
        }
    };

    // 将ref和input绑定
    render() {
        const safeDefaultValue = "helloWord";
        return (
            <div>
                <input ref={(a) => {
                    this.input1 = a;
                    console.log(this)
                }}/>
                <input type="text" ref={this.txtRef} defaultValue={safeDefaultValue}/>
                <button onClick={this.handleClick}>点</button>
            </div>
        );
    }
}

export default App;
